package com.appspot.zcmjqm.service;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.springframework.stereotype.Service;

import com.appspot.zcmjqm.app.model.Contact;

@Service
public class ContactServiceEMailImpl implements ContactService {

	public void sendContact(Contact contact) {
		Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        Message msg = new MimeMessage(session);
        try {
        	msg.setFrom(new InternetAddress("zachary.maddox@gmail.com", "Zachary Maddox"));
        	msg.addRecipient(Message.RecipientType.TO, new InternetAddress("zachary.maddox@gmail.com", "Zachary Maddox"));
        	msg.setSubject("Contact from Zach's Tech Stuff");
        	msg.setText(contact.getEmailBody());
        	Transport.send(msg);
        } catch(MessagingException e) {
        	throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
        	throw new RuntimeException(e);
		}
	}

}
